﻿/// <reference path="../../jquery.d.ts"/>
/// <reference path="../../jquerymobile.d.ts"/>
/// <reference path="../../geo.core.ts" />



//***********************************
// Core ViewModel                             
//***********************************
module Geo.ViewModel {
    export class Geocache {
        public static Site() : Geo.Enumerations.GeoCacheSiteTypes {
            return parseInt($('#ddlSite').val());
        }
        public static CacheCode() : string {
            return $('#txtCacheCode').val();
        }
        public static Save() {
            var newLog : Geo.Interfaces.ILogEntry = Geo.Core.LogEntryRepository.Add(Geo.Core.Current, Geo.Enumerations.ActionTypes.DropOff,
                Site(), CacheCode(), null, null);
            alert('Saved as ' + newLog.LogEntryLid);
        }
    }
    Geo.Core.OnAfterInitialize.add(function () {
        if (Geo.Core.Current.PrivateKey === null) {
            Geo.Core.Navigation.GoToEntry();
            return;
        } else if (Geo.Core.Current.ActionType === null) {
            Geo.Core.Navigation.GoToAction();
            return;
        }

        $('#btnNext').bind('click', function () {
            if (Geo.Core.Current.LogEntryLid) {
                Geo.Core.Current.CacheCode = Geo.ViewModel.Geocache.CacheCode();
                Geo.Core.LogEntryRepository.Update(Geo.Core.Current);
            } else {
                Geocache.Save();
            }
            Geo.Core.Navigation.GoToView();
            return false;
        });

        $('#btnBack').bind('click', function () {
            if (Geo.Core.Current.LogEntryLid)
                Geo.Core.Navigation.GoToAction();
            else
                Geo.Core.Navigation.GoToActionDetail(Geo.Core.Current.ActionType);
            return false;
        });
    });
}
